package cn.ahaiahaixx.dp.factory;

/**
 * 演示类
 * 
 * @author Aiden Pearce
 *
 */
public class Demo {
  public static void main(String[] args) {
    // Iteacher teacher=new JavaTeacher();
    // teacher.teach();
    // teacher=new JavaTeacher("李赣");
    // teacher.teach();
    // 通过工厂方法创建对象，不直接创建类型
    // 可以掩盖具体的实现类型，方便系统扩展
    Iteacher teacher = Boss.zhaopin("java");
    teacher.setName("李赣");
    teacher.teach();
    System.out.println(teacher.getClass());
    teacher = Boss.zhaopin("python");
    teacher.teach();
    System.out.println(teacher.getClass());
    System.out.println("===================");
    Iteacher t1 = Boss.zhaopin("java");
    System.out.println(t1.getClass());
    Iteacher t2 = Boss.zhaopin("java");
    System.out.println(t2.getClass());
    System.out.println(t1 == t2);
    System.out.println("==================单例模式的工厂方法");
    Iteacher t3 = Boss.szhaopin("java");
    Iteacher t4 = Boss.szhaopin("java");
    Iteacher t5 = Boss.szhaopin("网络");
    Iteacher t6 = Boss.szhaopin("python");
    t5.teach();
    System.out.println("同类型的是否单例：" + (t3 == t4));
    System.out.println("不同类型的是否单例：" + (t3 == t5));
    System.out.println("同类型的是否单例：" + (t5 == t6));

  }
}
